﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using RailwayDAL;
using RoutesAdministration.ViewModels;
using System.Collections.ObjectModel;

namespace RoutesAdministration.Views
{
    /// <summary>
    /// Interaction logic for TravelTimesAdministration.xaml
    /// </summary>
    public partial class TravelTimesAdministration : UserControl
    {
        RailwayCompanyEntities dbEntity = new RailwayCompanyEntities();
        private ViewModelMain vmMain;
        public TravelTimesAdministration()
        {
            InitializeComponent();
        }

        private void InsertButton_Click(object sender, RoutedEventArgs args)
        {
            try
            {
                TravelTime insertTravelTime = new TravelTime()
                {
                    Station1 = int.Parse(InsertStation1.Text),
                    Station2 = int.Parse(InsertStation2.Text),
                    Time = int.Parse(InsertTime.Text)
                };
                RailwayDBManager.CreateTravelTime(insertTravelTime);
                TravelTimesList.ItemsSource = dbEntity.TravelTimes.ToList();
            }
            catch (Exception e)
            {
                MessageBox.Show("Incorect Input");
            }
        }

        private void DeleteButton_Click(object sender, RoutedEventArgs e)
        {
            RailwayDBManager.DeleteTravelTime(int.Parse((sender as Button).DataContext.ToString()));
            TravelTimesList.ItemsSource = dbEntity.TravelTimes.ToList();
        }
    }
}
